function archive = updateArchive(archive, pop, funvalue)

  %  archive.NP; % the maximum size of the archive
 %   archive.pop; % the solutions stored in te archive
 %   archive.funvalues; % the function value of the archived solutions
 %   archive.np;%The number of stored solutions

if archive.NP == 0, return; end

if size(pop, 1) ~= size(funvalue,1), error('check it'); end

S=size(pop, 1);
for i=1:S  
    if archive.np<=archive.NP % the file is not full, it will be put into the file directly
       archive.pop(archive.np,:)=pop(i,:);
       archive.funvalues(archive.np)=funvalue(i);
       archive.np=archive.np+1;
    else
        R=ceil(rand()*archive.NP);
        if archive.funvalues(R)>=funvalue(i)   %The substituted solution is compared with the solution randomly selected from the archive, keeping the better of the two
            archive.pop(R,:)=pop(i,:);
            archive.funvalues(R)=funvalue(i);
        end
    end
end

